package com.edu.exam.entity.personnel.student;

import com.edu.exam.enums.common.Gender;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import java.time.LocalDate;

/**
 * 学生实体类
 * [所属模块] F-04 学籍管理模块
 * 对应数据库表：student_info
 */
@Entity
@Table(name = "student_info")
public class Student {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank(message = "学号不能为空")
    @Size(min = 3, max = 50, message = "学号长度必须在3-50个字符之间")
    @Column(name = "student_number", unique = true, nullable = false, length = 50)
    private String studentNumber;

    @NotBlank(message = "学生姓名不能为空")
    @Size(max = 100, message = "学生姓名长度不能超过100个字符")
    @Column(name = "name", nullable = false, length = 100)
    private String name;

    @NotNull(message = "性别不能为空")
    @Enumerated(EnumType.STRING)
    @Column(name = "gender", nullable = false, length = 10)
    private Gender gender;

    @NotBlank(message = "身份证号不能为空")
    @Pattern(regexp = "^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$",
             message = "身份证号格式不正确")
    @Column(name = "id_card", nullable = false, length = 18)
    private String idCard;

    @Column(name = "birth_date", nullable = false)
    private LocalDate birthDate;

    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式不正确")
    @Column(name = "phone_number", length = 20)
    private String phoneNumber;

    @Size(max = 100, message = "电子邮箱长度不能超过100个字符")
    @Column(name = "email", length = 100)
    private String email;

    @Size(max = 500, message = "家庭住址长度不能超过500个字符")
    @Column(name = "address", length = 500)
    private String address;

    @Size(max = 100, message = "紧急联系人长度不能超过100个字符")
    @Column(name = "emergency_contact", length = 100)
    private String emergencyContact;

    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "紧急联系电话格式不正确")
    @Column(name = "emergency_phone", length = 20)
    private String emergencyPhone;

    @Column(name = "deleted", nullable = false)
    private Boolean deleted = false;

    @Column(name = "version", nullable = false)
    private Integer version = 0;

    @Column(name = "created_time", nullable = false, updatable = false)
    private java.time.LocalDateTime createdTime;

    @Column(name = "updated_time", nullable = false)
    private java.time.LocalDateTime updatedTime;

    @Size(max = 50, message = "创建人长度不能超过50个字符")
    @Column(name = "created_by", length = 50)
    private String createdBy;

    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", length = 50)
    private String updatedBy;

}